<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <el-row :gutter="20">
        <!-- 第一行 -->
        <el-col :span="12">
          <!-- 搜索 -->
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable>
            <el-button slot="append" icon="el-icon-search" @click="getOrderList()"> </el-button>
          </el-input>
        </el-col>
        <!--  -->
        <el-col :span="4"> </el-col>
      </el-row>
      <!-- 表格区-->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="220"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="80"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status == '1'">付款了</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="80"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editBtn(scope.row.order_id)"></el-button>
            <el-button type="success" icon="el-icon-delete-location" size="mini" @click="showProgress"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
    </el-card>
    <!-- 修改地址的对话框 -->
    <el-dialog title="修改地址" :visible.sync="editdialogVisible" width="50%" @close="adressDialogColse">
      <el-form :model="addressRuleForm" :rules="addressRules" ref="addressref" label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <!-- 级联选择器 -->
          <el-cascader v-model="addressRuleForm.address1" :options="cityData" :props="propsParam"> </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressRuleForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="editdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEditAddress">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流对话框 -->
    <el-dialog title="提示" :visible.sync="progressDialogVisible" width="50%">
      <span>这是一段信息</span>
    </el-dialog>
  </div>
</template>
<script>
import cityData from "./citydata.js"
export default {
  data() {
    return {
      // 或者订单列表信息的参数
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      // 订单列表数据
      orderList: [],
      total: 0,
      // 修改地址的对话框的控制
      editdialogVisible: false,
      // 城市选择
      cityData,
      // 修改地址的表单
      addressRuleForm: {
        address1: [],
        address2: ""
      },
      // 验证修改地址的表单
      addressRules: {
        address1: [{ required: true, message: "请输选择地址", trigger: "blur" }],
        address2: [{ required: true, message: "请输入详细地址", trigger: "blur" }]
      },
      // props 的配置项
      propsParam: {
        value: "value",
        label: "label",
        children: "children"
      },
      // 修改地址的订单id
      orderId: "",
      progressDialogVisible: false,
      // 物流信息
      progressInfo: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) return this.$message("获取订单列表失败")
      this.$message.success("获取订单列表成功")
      this.total = res.data.total
      this.orderList = res.data.goods
      console.log(res)
    },
    // 分页 当数量改变
    handleSizeChange(newsize) {
      this.queryInfo.pagesize = newsize
      this.getOrderList()
    },
    // 分页 当当前页改变
    handleCurrentChange(newnum) {
      this.queryInfo.pagenum = newnum
      this.getOrderList()
    },
    // 订单搜索
    search() {
      console.log(this.queryInfo.query)
      this.getOrderList()
    },
    // 关闭修改地址的对话框，清空表单内容
    adressDialogColse() {
      this.$refs.addressref.resetFields()
    },
    // 点击修改地址按钮
    editBtn(id) {
      this.orderId = id
      this.editdialogVisible = true
    },
    // 修改地址的确认提交地址
    submitEditAddress() {
      this.editdialogVisible = false
    },
    // 展示物流对话框
    async showProgress() {
      this.progressDialogVisible = true
    }
  }
}
</script>
<style scoped>
.el-table {
  margin-top: 30px;
}
</style>
